package wechat.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import wechat.resources.InstanceResource;
import wechat.service.UserService;
import wechat.service.base.BaseRequest;

@Service
public class IUserService extends BaseRequest implements UserService {

	private Logger log = LoggerFactory.getLogger(IUserService.class);
	
	@Autowired
	IAccessTokenService accessTokenService;
	
	public String createUser(InstanceResource instanceResource,JSONObject jsonParam) throws Exception{
		log.info("IUserService -- addUser  jsonParam=" + jsonParam);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		String param = jsonParam.toJSONString();
		
		String result = super.createUser(access_token, param, isCheck);
		return result;
	}
	
	public String updateUser(InstanceResource instanceResource,JSONObject jsonParam) throws Exception{
		log.info("IUserService -- updateUser  jsonParam=" + jsonParam);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		String param = jsonParam.toJSONString();
		
		String result = super.updateUser(access_token, param, isCheck);
		return result;
	}
	
	public String deleteUser(InstanceResource instanceResource,String userid) throws Exception{
		log.info("IUserService -- deleteUser  userid=" + userid);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		
		String result = super.deleteUser(access_token, userid, isCheck);
		return result;
	}
	
	
	public String batchdeleteUser(InstanceResource instanceResource,JSONObject jsonParam) throws Exception{
		log.info("IUserService -- batchdeleteUser  jsonParam=" + jsonParam);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		String param = jsonParam.toJSONString();
		
		String result = super.batchdeleteUser(access_token, param, isCheck);
		return result;
	}
	
	public String getUser(InstanceResource instanceResource,String userid) throws Exception{
		log.info("IUserService -- getUser  userid=" + userid);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		
		String result = super.getUser(access_token, userid, isCheck);
		return result;
	}
	
	
	public String simplelistUser(InstanceResource instanceResource,String department_id,String fetch_child,String status) throws Exception{
		log.info("IUserService -- simplelistUser  department_id=" + department_id + " fetch_child=" +fetch_child + " status=" +status);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		
		String result = super.simplelistUser(access_token, department_id, fetch_child, status, isCheck);
		return result;
	}
	
	
	public String listUser(InstanceResource instanceResource,String department_id,String fetch_child,String status) throws Exception {
		log.info("IUserService -- listUser  department_id=" + department_id + " fetch_child=" +fetch_child + " status=" +status);
		
		String access_token = accessTokenService.getAccessToken(instanceResource).getAccessToken();
		boolean isCheck = false;
		
		String result = super.listUser(access_token, department_id, fetch_child, status, isCheck);
		return result;
	}

}
